//
//  BaseViewController.m
//  Delicious2
//
//  Created by FSD on 16/1/6.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "BaseViewController.h"
#import "SearchViewController.h"
@interface BaseViewController ()

@end

@implementation BaseViewController

-(void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.navigationController.navigationBar.barTintColor = kColor;
    [self.navigationController.navigationBar setTitleTextAttributes:
     @{NSFontAttributeName:[UIFont systemFontOfSize:20], NSForegroundColorAttributeName:[UIColor whiteColor]}];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"SearchImage"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]style:UIBarButtonItemStylePlain target:self action:@selector(searchBarButtonDidPress:)];
//    通知
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(receiveNotification:) name:@"changeColor" object:nil];

}

#pragma mark ----- 夜间模式改变颜色方法
-(void)receiveNotification:(NSNotification *)sender {
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *mode = [user objectForKey:@"NightMode"];
    if ([mode isEqualToString:@"Night"]) {
        self.navigationController.navigationBar.barTintColor = [UIColor grayColor];
    } else {
        self.navigationController.navigationBar.barTintColor = kColor;
    }
}
- (void)viewWillAppear:(BOOL)animated {
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *passWord = [user objectForKey:@"NightMode"];
    if ([passWord isEqualToString:@"Night"]) {
        self.navigationController.navigationBar.barTintColor = [UIColor grayColor];
    } else {
        self.navigationController.navigationBar.barTintColor = kColor;
    }
}


- (void)searchBarButtonDidPress:(UIButton *)button {
    SearchViewController *searchVC = [[SearchViewController alloc] init];
    
    [self.navigationController pushViewController:searchVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
